// confirm dialog service
var app = angular.module('app');

app.factory('confirmDialogService', ['$q', '$modal', '$translate',
    function ($q, $modal, $translate) {
        var confirmDialogService = {};

        confirmDialogService.showDialog = function (title, description, size, data) {
            var deferred = $q.defer();
            var instance = $modal.open({
                templateUrl: 'tpl/confirmDialog.html',
                controller: 'confirmDialogCtrl',
                size: size,
                backdrop: 'static',
                resolve: {
                    title: function () {
                        return title || $translate.instant('strings.dialog.title');
                    },
                    description: function () {
                        return description;
                    }
                }
            });

            instance.result.then(function () {
                deferred.resolve(data);
            }, function () {
                deferred.reject();
            });

            return deferred.promise;
        };

        return confirmDialogService;
    }]);

app.controller('confirmDialogCtrl', ['$scope', '$modalInstance', 'title', 'description',
    function ($scope, $modalInstance, title, description) {
        $scope.title = title;
        $scope.description = description;
        $scope.ok = function () {
            $modalInstance.close();
        };
        $scope.cancel = function () {
            $modalInstance.dismiss();
        }
    }]);